<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="security"%>
<!-- Messages: style can be found in dropdown.less-->
<li class="dropdown messages-menu"><a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-envelope"></i> <span
		class="label label-success"></span>
</a>
	<ul class="dropdown-menu">
		<li class="header"></li>
		<li>
			<!-- inner menu: contains the actual data -->
			<ul class="menu">
				<%-- <li><a href="viewMessage.html?id=">
						<div class="pull-left">
							<img src="<c:url value='/images/email.png'/>" class="img-circle" />
						</div>
						<h4>
							Support Team <small><i class="fa fa-clock-o"></i> 5 mins</small>s
						</h4>
						<p>Why not buy a new awesome theme?</p>
				</a></li> --%>
			</ul>
		</li>
		<li class="footer"><a href="getMailBox.html?mode=INBOX"><spring:message code="admin.message.see.all.message" /></a></li>
	</ul></li>
<!-- Notifications: style can be found in dropdown.less -->
<li class="dropdown notifications-menu"><a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-warning"></i> <span
		class="label label-warning"></span>
</a>
	<ul class="dropdown-menu">
		<li class="header"></li>
		<li>
			<!-- inner menu: contains the actual data -->
			<ul class="menu">
				<!-- <li><a href="#"> <i class="ion ion-ios7-cart success"></i> 25 sales made
				</a></li> -->
			</ul>
		</li>
		<li class="footer"><a href="#"><spring:message code="admin.txn.see.all.txn" /></a></li>
	</ul></li>
<!-- Tasks: style can be found in dropdown.less -->
<!-- <li class="dropdown tasks-menu"><a href="#" class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-tasks"></i> <span
		class="label label-danger">9</span>
</a>
	<ul class="dropdown-menu">
		<li class="header">You have 9 tasks</li>
		<li>
			inner menu: contains the actual data
			<ul class="menu">
				<li>
					Task item <a href="#">
						<h3>
							Design some buttons <small class="pull-right">20%</small>
						</h3>
						<div class="progress xs">
							<div class="progress-bar progress-bar-aqua" style="width: 20%" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
								<span class="sr-only">20% Complete</span>
							</div>
						</div>
				</a>
				</li>
				end task item
				<li>
					Task item <a href="#">
						<h3>
							Create a nice theme <small class="pull-right">40%</small>
						</h3>
						<div class="progress xs">
							<div class="progress-bar progress-bar-green" style="width: 40%" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
								<span class="sr-only">40% Complete</span>
							</div>
						</div>
				</a>
				</li>
				end task item
				<li>
					Task item <a href="#">
						<h3>
							Some task I need to do <small class="pull-right">60%</small>
						</h3>
						<div class="progress xs">
							<div class="progress-bar progress-bar-red" style="width: 60%" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
								<span class="sr-only">60% Complete</span>
							</div>
						</div>
				</a>
				</li>
				end task item
				<li>
					Task item <a href="#">
						<h3>
							Make beautiful transitions <small class="pull-right">80%</small>
						</h3>
						<div class="progress xs">
							<div class="progress-bar progress-bar-yellow" style="width: 80%" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100">
								<span class="sr-only">80% Complete</span>
							</div>
						</div>
				</a>
				</li>
				end task item
			</ul>
		</li>
		<li class="footer"><a href="#">View all tasks</a></li>
	</ul></li> -->
<script type="text/javascript">
	$(document).ready(function() {
		checkEmailAlert();
		checkTxnAlert();
		window.setInterval(function(){checkEmailAlert();},60*2*1000);
		window.setInterval(function(){checkTxnAlert();},60*2*1000);
	});

	function checkEmailAlert() {
		$.ajax({
					url : 'checkEmailAlert.html',
					type : 'POST',
					dataType : 'json',
					success : function(response) {
						if (response.length > 0) {
							$('.dropdown.messages-menu .label-success').text(
									response.length);
							$('a[href="getMailBox.html?mode=INBOX"] .bg-yellow').text(response.length);
							$('#newMail').text(response.length);
							$('.messages-menu .dropdown-menu .menu').empty();
							for (var i = 0; i < response.length; i++) {
								var message = response[i];
								$('.messages-menu .dropdown-menu .menu')
										.append(
												'<li><a href="readEmail.html?id='
														+ message.id
														+ '&mode=INBOX"> <div class="pull-left"><img src="${pageContext.servletContext.contextPath}/images/email.png" class="img-circle" /></div><h4>'
														+ message.from
														+ '</h4><p>'+message.subject+'</p></a></li>');
							}
						} else {
							$('.dropdown.messages-menu .label-success').text('');
							$('a[href="getMailBox.html?mode=INBOX"] .bg-yellow').text('');
							$('#newMail').text(response.length);
						}
						$('.messages-menu .dropdown-menu .header').text(
										'<spring:message javaScriptEscape="true" code="admin.message.you.have" /> '
												+ response.length
												+ ' <spring:message javaScriptEscape="true" code="admin.message.message" />');
					},
					error : function() {
					}
				});

	};
	
	function checkTxnAlert() {
		$.ajax({
					url : 'checkTxnAlert.html',
					type : 'POST',
					dataType : 'json',
					success : function(response) {
						if (response.length > 0) {
							$('.dropdown.notifications-menu .label-warning').text(
									response.length);
							$('#txnNewCount').text(response.length);
							$('.notifications-menu .dropdown-menu .menu').empty();
							for (var i = 0; i < response.length; i++) {
								var txn = response[i];
								$('.notifications-menu .dropdown-menu .menu')
										.append(
												'<li><a href="viewTransaction.html?id='
														+ txn.id
														+ '"> <i class="ion ion-ios7-cart success"></i>'
														+ txn.transactionRefNum
														+ '</a></li>');
							}
						} else {
							$('.dropdown.notifications-menu .label-warning').text('');
							$('#txnNewCount').text('');
						}
						$('.notifications-menu .dropdown-menu .header').text(
										'<spring:message javaScriptEscape="true" code="admin.txn.you.have" /> '
												+ response.length
												+ ' <spring:message javaScriptEscape="true" code="admin.txn.transaction" />');
					},
					error : function() {
					}
				});

	};
</script>